package workbench.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import util.JsonUtil;
import workbench.service.TranService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ChartController {
    @Autowired
    private TranService tranService;
    @RequestMapping(value = "/getCharts")
    @ResponseBody
    public String getCharts() throws JsonProcessingException {
        List<Map> list=tranService.getCharts();
        long count=0;
        for(Map m:list){
            count+=(Long) m.get("value");
        }
        Map<String,Object> map=new HashMap<>();
        map.put("total",String.valueOf(count));
        map.put("dataList",list);
        String json= JsonUtil.writeValueAsString(map);
        return json;
    }
}
